#include "CGETimer.h"

CGETimer::CGETimer(void)
{
	m_StartTime = 0;
	m_Started = false;
	m_PauseTime = 0;
	m_Paused = false;
}

CGETimer::~CGETimer(void)
{
}

void CGETimer::Start()
{
	//Start the timer
	m_Started = true;

	//Unpause the timer
	m_Paused = false;

	//Get the current clock time
	m_StartTime = SDL_GetTicks();    
}

void CGETimer::Stop()
{
	//Stop the timer
	m_Started = false;

	//Unpause the timer
	m_Paused = false;    
}

void CGETimer::Pause()
{
	//If the timer is running and isn't already paused
	if( ( m_Started == true ) && ( m_Paused == false ) )
	{
		//Pause the timer
		m_Paused = true;

		//Calculate the paused ticks
		m_PauseTime = SDL_GetTicks() - m_StartTime;
	}
}

void CGETimer::Unpause()
{
	//If the timer is paused
	if( m_Paused == true )
	{
		//Unpause the timer
		m_Paused = false;

		//Reset the starting ticks
		m_StartTime = SDL_GetTicks() - m_PauseTime;

		//Reset the paused ticks
		m_PauseTime = 0;
	}
}

int CGETimer::GetTicks()
{
	//If the timer is running
	if( m_Started == true )
	{
		//If the timer is paused
		if( m_Paused == true )
		{
			//Return the number of ticks when the timer was paused
			return m_PauseTime;
		}
		else
		{
			int xxx = SDL_GetTicks() - m_StartTime;
			//Return the current time minus the start time
			return SDL_GetTicks() - m_StartTime;
		}    
	}
	//If the timer isn't running
	return 0;    
}






